import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  DeviceOrientation _currentOrientation = DeviceOrientation.portraitUp;
  void _incrementCounter() {
    setState(() {
      if (_currentOrientation == DeviceOrientation.portraitUp) {
        _currentOrientation = DeviceOrientation.landscapeLeft;
      } else {
        _currentOrientation = DeviceOrientation.portraitUp;
      }
      SystemChrome.setPreferredOrientations([_currentOrientation]);
    });
  }

  createViewItem(len, w, h) {
    List<Widget> list = [];
    for (var i = 0; i < len; i++) {
      list.add(Container(width: w, height: h, color: Colors.green));
    }
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter app'),
      ),
      body:SingleChildScrollView(
        child:Center(
          child: Wrap(
            spacing: 10.0,
            runSpacing: 10.0,
            alignment: WrapAlignment.center,
            children: createViewItem(20.0, 150.0, 150.0),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
